<!-- Copyright (c) 2002 by ObjectLearn. All Rights Reserved. -->
<%@page import="com.zucc.core.po.Reservation"%>
<%@page import="com.mysql.fabric.xmlrpc.base.Data"%>
<%@page import="org.springframework.ui.Model"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>   
    <%@	page import="java.util.List" %>
    <%@	page import="com.zucc.core.po.MeetingRoom" %> 
<%@ page trimDirectiveWhitespaces="true"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="zucc" uri="http://zucc.com/common/"%>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() 
	                   + ":" + request.getServerPort() + path + "/";
%>
<html>
	<head>
		<title>Welcome</title>
		<!-- 引入css样式文件 -->
	<!-- Bootstrap Core CSS -->
	<link href="<%=basePath%>css/bootstrap.min.css" rel="stylesheet" />
	<!-- MetisMenu CSS -->
	<link href="<%=basePath%>css/metisMenu.min.css" rel="stylesheet" />
	<!-- DataTables CSS -->
	<link href="<%=basePath%>css/dataTables.bootstrap.css" rel="stylesheet" />
	<!-- Custom CSS -->
	<link href="<%=basePath%>css/sb-admin-2.css" rel="stylesheet" />
	<!-- Custom Fonts -->
	<link href="<%=basePath%>css/font-awesome.min.css" rel="stylesheet" type="text/css" />
	<link href="<%=basePath%>css/boot-crm.css" rel="stylesheet" type="text/css" />
		
	</head>
	<body>
	<div id="page-wrapper">
	<a href="${pageContext.request.contextPath }/mr/list.action" class="btn btn-primary">返回</a>
	<a href="#" class="btn btn-primary" data-toggle="modal" 
		           data-target="#newRsDialog" onclick="clearRs()">预约会议室</a>
		<div class="panel panel-default">
					<div class="panel-heading">会议室信息列表</div>
					<!-- /.panel-heading -->
					<table class="table table-bordered table-striped">
						<thead>
							<tr>
								<th>会议室名称</th>
								<th>预约时间</th>
								<th>预约时长</th>
								
							</tr>
						</thead>
						<tbody>
						<c:forEach items="${res}" var="res">
								<tr>
									<td>${res.mName}</td>
									<td>${res.resDate}</td>
									<td>${res.mTim}小时</td>
									<td>
										<a href="#" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#mrEditDialog" onclick= "editRs(${res.resId})">查看或更改预约信息</a>
										<a href="#" class="btn btn-danger btn-xs" onclick="deleteMR(${res.resId})">删除</a>
										
									</td>
								</tr>
							</c:forEach>
						</tbody>
					</table>
					
					<!-- /.panel-body -->
				</div>
			</div>
			<!-- 创建 -->
			<div class="modal fade" id="newRsDialog" tabindex="-1" role="dialog"
	aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
				<h4 class="modal-title" id="myModalLabel">预约会议室</h4>
			</div>
			<div class="modal-body">
				<form class="form-horizontal" id="new_rs_form">
					<div class="form-group">
						<label for="new_rsFrom" style="float:left;padding:7px 15px 0 27px;">会议室</label> 
						<div class="col-sm-10">
							<select	class="form-control" id="mRoomId" name="mRoomId">
								<option value="">--请选择--</option>
								<c:forEach items="${rm}" var="rm">
									<option value="${rm.m_R_id}"<c:if test="${rm.m_R_id == mId}">selected</c:if>>
									${rm.m_Name}									
									</option>
								</c:forEach>
							</select>
						</div>
					</div>
					
					<div class="form-group">
						<label for="new_size" class="col-sm-2 control-label">预约时间</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="resDate" placeholder="yyyy-MM-dd HH:mm:ss" name="resDate" />
						</div>
					</div>
					
					<div class="form-group">
						<label for="new_size" class="col-sm-2 control-label">预约时长</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="mTim" placeholder="小时" name="mTim" />
						</div>
					</div>
					
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				<button type="button" class="btn btn-primary" onclick="createRs()">预约</button>
			</div>
		</div>
	</div>
</div>
			<!-- 查看设置预约表 -->
			<div class="modal fade" id="mrEditDialog" tabindex="-1" role="dialog"
	aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
				<h4 class="modal-title" id="myModalLabel">预约表</h4>
			</div>
			<div class="modal-body">
				<form class="form-horizontal" id="edit_rs_form">
					<input type="hidden" id="edit_rs_id" name="resId"/>
					<div class="form-group">
						<label for="res_mrName" class="col-sm-2 control-label">会议室名称</label>
						<div class="col-sm-10">
							<input type="text" readOnly="true" class="form-control" id="edit_mrName" placeholder="会议室名称" name="mName" />
						</div>
					</div>
					<div class="form-group">
						<label for="res_userName:" class="col-sm-2 control-label">预约人</label>
						<div class="col-sm-10">
							<input type="text" readOnly="true" class="form-control" id="edit_userName" placeholder="预约人" name="userName" />
						</div>
					</div>
					<div class="form-group">
						<label for="res_Date" class="col-sm-2 control-label">预约时间</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_Date" placeholder="预约时间" name="resDate" />
						</div>
					</div>
					<div class="form-group">
						<label for="res_Tim" class="col-sm-2 control-label">预约时长/h</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_tim" placeholder="预约时长" name="mTim" />
						</div>
					</div>
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				<button type="button" class="btn btn-primary" onclick="updateRs()">保存修改</button>
			</div>
		</div>
	</div>
</div>
			
			<!-- 引入js文件 -->
		<!-- jQuery -->
		<script src="<%=basePath%>js/jquery-1.11.3.min.js"></script>
		<!-- Bootstrap Core JavaScript -->
		<script src="<%=basePath%>js/bootstrap.min.js"></script>
		<!-- Metis Menu Plugin JavaScript -->
		<script src="<%=basePath%>js/metisMenu.min.js"></script>
		<!-- DataTables JavaScript -->
		<script src="<%=basePath%>js/jquery.dataTables.min.js"></script>
		<script src="<%=basePath%>js/dataTables.bootstrap.min.js"></script>
		<!-- Custom Theme JavaScript -->
		<script src="<%=basePath%>js/sb-admin-2.js"></script>
		<!-- 编写js代码 -->
		<script type="text/javascript">
		function createRs() {
			$.post("<%=basePath%>/mr/rs/create.action",
			$("#new_rs_form").serialize(),function(data){
			        if(data =="OK"){
			            alert("预约成功！");
			            window.location.reload();
			        }else{
			            alert("预约失败！会议室正忙");
			            window.location.reload();
			        }
			    });
			}
		
		function deleteMR(id) {
		    if(confirm('确实要删除该该预约吗?')) {
		$.post("<%=basePath%>mr/rs/delete.action",{"id":id},
		function(data){
		            if(data =="OK"){
		                alert("预约删除成功！");
		                window.location.reload();
		            }else{
		                alert("删除预约失败！");
		                window.location.reload();
		            }
		        });
		    }
		}
		
		// 通过id获取设置的会议室信息
		function editRs(id) {
		    $.ajax({
		        type:"get",
		        url:"<%=basePath%>mr/rs/getRsById.action",
		        data:{"id":id},

		        success:function(data) {
		            
		        	$("#edit_rs_id").val(data.resId);
		            $("#edit_mrName").val(data.mName);
		            $("#edit_Date").val(data.resDate);
		            $("#edit_tim").val(data.mTim);
		            $("#edit_userName").val(data.nickName);
		            
		        }
		    });
		}
		function updateRs() {
			$.post("<%=basePath%>mr/rs/updateMR.action",$("#edit_rs_form").serialize(),function(data){
				if(data =="OK"){
					alert("预约表信息更新成功！");
					window.location.reload();
				}else{
					alert("预约表信息更新失败！");
					window.location.reload();
				}
			});
		}
		</script>
	</body>
</html>
